<?php

class subcategoryActions extends sfActions {

    public function executeIndex(sfWebRequest $request){
        $this->subcategories = SubcategoryPeer::doSelectWithI18n(new Criteria());
    }

    public function executeNew(sfWebRequest $request){
        $this->categories = CategoryPeer::doSelectWithI18n(new Criteria());
    }

    public function executeNewSave(sfWebRequest $request){
        $desc_en = $request->getParameter('desc_en');
        $desc_es = $request->getParameter('desc_es');
        $category_id = $request->getParameter('category');
        $object = new Subcategory();
        $object->setDescription($desc_en,'en');
        $object->setDescription($desc_es,'es');
        $object->setCategoryId($category_id);
        $object->setFlags('[-]*[-]*[-]');
        $object->save();
        return $this->redirect('@subcategory');
    }

    public function executeEdit(sfWebRequest $request){
        $id = $request->getParameter('id');
        $this->object = SubcategoryPeer::retrieveByPK($id);
        $this->categories = CategoryPeer::doSelectWithI18n(new Criteria());
    }

    public function executeEditSave(sfWebRequest $request){
        $id = $request->getParameter('uid');
        $udesc_en = $request->getParameter('udesc_en');
        $udesc_es = $request->getParameter('udesc_es');
        $category_id = $request->getParameter('ucategory');
        $object = SubcategoryPeer::retrieveByPK($id);
        $object->setDescription($udesc_en,'en');
        $object->setDescription($udesc_es,'es');
        $object->setCategoryId($category_id);
        $object->setFlags('[-]*[-]*[-]');
        $object->save();
        return $this->redirect('@subcategory');
    }

    public function executeDelete(sfWebRequest $request){
        $id = $request->getParameter('id');
        return $this->redirect('@subcategory');
    }

}